<template>
	<view class="content">
		<uni-section title="微信安装包" type="line">
			<view class="uni-padding-wrap uni-common-mt">
				<uni-segmented-control :current="current" :values="items" :style-type="styleType"
					:active-color="activeColor" @clickItem="onClickItem" />
			</view>
			<uni-notice-bar showIcon scrollable text="微信正式版、测试版安卓包下载"></uni-notice-bar>
			<view class="content">
				<view v-if="current === 0">
					<ul class="update-list" id="updateList">
						<li class="update-item  loaded" v-for="(item,index) in lastlist">
							<h3 class="update-name">{{item.name}}</h3>
							<p class="update-meta">
								版本: {{item.version}}<br>
								大小: {{ bytesToMB(item.size) }} MB<br>
								发布日期: {{item.publish_date}}<br>
								<!-- 更新时间: 2524/05/29 09:44 -->
							</p>
							<div class="update-link-btn" data-index="0">
								<uni-link :href="item.url" downlaod="{{item.url}}" text="官方下载" showUnderLine="false"
									color="#ffffff" copyTips="已自动复制网址，请在手机浏览器里粘贴该网址"></uni-link>
							</div>

						</li>
						<uni-load-more :status="status" :content-text="contentText" />

					</ul>
				</view>
				<view v-if="current === 1">
					<ul class="update-list" id="updateList">
						<li class="update-item  loaded" v-for="(item,index) in betalist">
							<h3 class="update-name">{{item.name}}</h3>
							<p class="update-meta">
								版本: {{item.version}}<br>
								大小: {{ bytesToMB(item.size) }} MB<br>
								发布日期: {{item.publish_date}}<br>
								<!-- 更新时间: 2524/05/29 09:44 -->
							</p>
							<div class="update-link-btn" data-index="0">
								<uni-link :href="item.url" downlaod="{{item.url}}" text="官方下载" showUnderLine="false"
									color="#ffffff" copyTips="已自动复制网址，请在手机浏览器里粘贴该网址"></uni-link>
							</div>

						</li>
						<uni-load-more :status="status" :content-text="contentText" />
					</ul>
				</view>
				<!-- 		<view v-if="current === 2">开发中</view>
				<view v-if="current === 3">开发中</view> -->
			</view>
		</uni-section>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				items: ['安卓微信正式版', '安卓微信测试版'],
				styles: [{
						value: 'button',
						text: '按钮',
						checked: true
					},
					{
						value: 'text',
						text: '文字'
					}
				],
				colors: ['#007aff', '#4cd964', '#dd524d'],
				current: 0,
				colorIndex: 0,
				activeColor: '#007aff',
				styleType: 'button',
				lastlist: [],
				betalist: [],
				status: 'more',
				contentText: {
					contentdown: '查看更多',
					contentrefresh: '加载中',
					contentnomore: '没有更多'
				},
				total: 0,
				pageNum: 1,
				pageSize: 10,
			}
		},
		onLoad() {

			this.getlast();
			this.getbeta();
		},
		methods: {
			//上拉加载
			onReachBottom() {
				if (this.status == 'noMore') {
					return;
				}
				this.pageNum++;
				console.log(this.pageNum)
				this.getlast();
				this.getbeta();
			},
			//下拉刷新
			onPullDownRefresh() {
				uni.stopPullDownRefresh();
				this.lastlist = [];
				this.betalist = [];
				this.getlast();
				this.getbeta();
			},
			bytesToMB(bytes) {
				return (bytes / (1024 * 1024)).toFixed(2);
			},
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex
				}
			},
			styleChange(e) {
				if (this.styleType !== e.detail.value) {
					this.styleType = e.detail.value
				}
			},
			colorChange(e) {
				if (this.styleType !== e.detail.value) {
					console.log(e.detail.value);
					this.activeColor = e.detail.value
				}
			},
			getlast() {
				uni.request({
					url: 'https://update.wxredcover.cn/proxy/release', //仅为示例，并非真实接口地址。
					success: (res) => {
						uni.showLoading({
							title: '加载中'
						});
						this.lastlist = res.data;
						setTimeout(function() {
							uni.hideLoading();
						}, 2000);

					}
				});
			},
			getbeta() {
				uni.request({
					url: 'https://update.wxredcover.cn/proxy/beta', //仅为示例，并非真实接口地址。
					success: (res) => {
						uni.showLoading({
							title: '加载中'
						});
						this.betalist = res.data;
						setTimeout(function() {
							uni.hideLoading();
						}, 2000);
					}
				});
			}
		}
	}
</script>

<style>
	body {
		font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
		max-width: 1000px;
		margin: 0 auto;
		padding: 20px;
		background: #f5f5f5;
		color: #333;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
	}

	.header {
		position: sticky;
		top: 0;
		background: #fff;
		z-index: 20;
		padding: 15px 20px;
		border-radius: 12px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
		margin-bottom: 20px;
	}

	.author-container {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 15px;
		padding-bottom: 10px;
		border-bottom: 1px solid #eee;
	}

	.author-text {
		font-size: 16px;
		color: #666;
	}

	.author-text span {
		color: rgb(0, 122, 255);
		font-weight: 500;
	}

	.wx-qrcode {
		width: 120px;
		height: 120px;
		border-radius: 8px;
	}

	.tab-container {
		display: flex;
		gap: 10px;
	}

	.tab {
		flex: 1;
		text-align: center;
		padding: 12px 0;
		font-size: 16px;
		color: #666;
		cursor: pointer;
		background: #f0f0f0;
		border-radius: 8px;
	}

	.tab.active {
		color: #fff;
		background: rgb(0, 122, 255);
		font-weight: 500;
	}

	.search-container {
		background: #fff;
		padding: 15px 20px;
		border-radius: 12px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
		margin-bottom: 20px;
		display: flex;
		align-items: center;
		gap: 10px;
	}

	#searchInput {
		flex: 1;
		padding: 12px 15px;
		font-size: 16px;
		border: none;
		border-radius: 8px;
		background: #f0f0f0;
		box-sizing: border-box;
	}

	#searchInput:focus {
		background: #fff;
		outline: 1px solid rgb(0, 122, 255);
	}

	.refresh-btn {
		padding: 8px 16px;
		background: rgb(0, 122, 255);
		color: white;
		border: none;
		border-radius: 6px;
		font-size: 14px;
		cursor: pointer;
		transition: background 0.2s ease;
		position: relative;
		overflow: hidden;
	}

	.refresh-btn:hover {
		background: rgb(0, 122, 255);
	}

	.refresh-btn:disabled {
		background: #cccccc;
		cursor: not-allowed;
	}

	.refresh-btn.loading::after {
		content: '';
		position: absolute;
		width: 16px;
		height: 16px;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		border: 2px solid #fff;
		border-top: 2px solid transparent;
		border-radius: 50%;
		animation: spin 1s linear infinite;
	}

	@keyframes spin {
		0% {
			transform: translate(-50%, -50%) rotate(0deg);
		}

		100% {
			transform: translate(-50%, -50%) rotate(360deg);
		}
	}

	.refresh-btn.loading span {
		visibility: hidden;
	}

	.chart-container {
		background: #fff;
		padding: 20px;
		border-radius: 12px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
		margin-bottom: 20px;
		max-height: 400px;
	}

	canvas {
		max-width: 100%;
		max-height: 100%;
	}

	.update-list {
		list-style: none;
		padding: 0;
		flex: 1;
	}

	.update-item {
		background: #fff;
		padding: 20px;
		margin-bottom: 15px;
		border-radius: 12px;
		box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
		position: relative;
	}

	.update-item.latest::after {
		content: '最新';
		position: absolute;
		top: 10px;
		right: 10px;
		background: rgb(0, 122, 255);
		color: #fff;
		padding: 4px 8px;
		border-radius: 4px;
		font-size: 12px;
		font-weight: 500;
	}

	.update-name {
		font-size: 20px;
		margin: 0 0 10px 0;
		color: rgb(0, 122, 255);
		font-weight: 500;
	}

	.update-meta {
		color: #666;
		font-size: 14px;
		margin: 10px 0;
		line-height: 2;
	}

	.update-link-btn {
		display: inline-block;
		margin-top: 8px;
		padding: 6px 12px;
		background: rgb(0, 122, 255);
		color: white;
		text-decoration: none;
		border-radius: 6px;
		font-size: 14px;
		cursor: pointer;
	}

	.update-link-btn:hover {
		background: rgb(0, 122, 255);
	}

	.update-url {
		display: none;
		margin-top: 8px;
		padding: 8px 12px;
		background: #f0f0f0;
		border-radius: 6px;
		font-size: 14px;
		color: #444;
		word-break: break-all;
		cursor: pointer;
		position: relative;
	}

	.update-url.visible {
		display: block;
	}

	.copied-tip {
		position: absolute;
		left: 50%;
		top: 50%;
		transform: translate(-50%, -50%);
		background: rgb(0, 122, 255);
		color: white;
		padding: 8px 16px;
		border-radius: 6px;
		font-size: 16px;
		opacity: 0;
		transition: opacity 0.3s ease;
		pointer-events: none;
	}

	.loading {
		text-align: center;
		padding: 20px;
		color: rgb(0, 122, 255);
		font-size: 16px;
		height: 20px;
		line-height: 20px;
	}

	.footer {
		position: sticky;
		bottom: 0;
		background: #fff;
		padding: 5px 20px;
		text-align: center;
		font-size: 12px;
		color: #999;
		border-top: 1px solid #eee;
		z-index: 10;
		line-height: 1.5;
	}

	.footer a {
		color: #999;
		text-decoration: none;
		margin: 0 5px;
	}

	.footer a:hover {
		color: #666;
		text-decoration: underline;
	}

	@media (max-width: 600px) {
		body {
			padding: 15px;
		}

		.header,
		.search-container {
			padding: 10px 15px;
		}

		.author-container {
			flex-direction: column;
			align-items: flex-start;
		}

		.wx-qrcode {
			margin-top: 10px;
			width: 90px;
			height: 90px;
		}

		.author-text {
			font-size: 18px;
		}

		.tab {
			font-size: 16px;
			padding: 10px 0;
		}

		.chart-container {
			padding: 10px;
			max-height: 300px;
		}

		.update-item {
			padding: 15px;
			margin-bottom: 10px;
		}

		.update-name {
			font-size: 20px;
		}

		.update-meta {
			font-size: 16px;
			margin: 8px 0;
			line-height: 1.8;
		}

		.update-link-btn,
		.update-url {
			font-size: 16px;
			padding: 8px 12px;
		}

		#searchInput {
			padding: 12px 15px;
			font-size: 18px;
		}

		.refresh-btn {
			font-size: 16px;
			padding: 8px 12px;
		}

		.copied-tip {
			font-size: 18px;
			padding: 8px 16px;
		}

		.loading {
			font-size: 18px;
		}

		.update-item.latest::after {
			font-size: 14px;
		}

		.footer {
			font-size: 14px;
			padding: 4px 15px;
		}
	}
</style>